package vistas;

import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import controller.ControllerPrincipal;

import beans.EntidadBean;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class ModificacionCliente extends DetalleCliente {

	public ModificacionCliente(EntidadBean cliente) {
		super(cliente);

	}

	@Override
	protected void initGUI() {
		super.initGUI();

		getContentPane().remove(btnEliminar);
		btnModificar.setText("GRABAR");
		labelTitulo.setText("Modificacion de Usuario");
		this.setSize(546, 344);
		ActionListener[] actions = btnModificar.getActionListeners();
		// limpio el comportamiento, luego vamso a cambiarlo a un metodo q se
		// reimplementa
		for (ActionListener act : actions) {
			btnModificar.removeActionListener(act);
		}

		btnModificar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					if (ControllerPrincipal.getInstancia()
							.validarClienteExistenteByCuil(jTextCuil.getText())) {
						ControllerPrincipal.getInstancia().modificarCliente(
								cliente, jTextIVA.getText(), JTextRS.getText());
						JOptionPane.showMessageDialog(null,
								"El usuario fue modificado satisfactoriamente",
								"", JOptionPane.INFORMATION_MESSAGE);
						_volver();
					} else {
						JOptionPane.showMessageDialog(null,
								"El usuario ya existe en el sistema", "Error",
								JOptionPane.INFORMATION_MESSAGE);
					}
				} catch (HeadlessException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
	}

	@Override
	protected void deshabilitarCampos() {
		// mantengo DNI bloqueado
		jTextCuil.disable();
	}

}
